<script setup>
import { inject } from 'vue';

// 从根组件注入数据，无需经过中间组件传递
const theme = inject('theme');
const toggleTheme = inject('toggleTheme');
</script>

<template>
  <div class="deep-child">
    <div class="injected-info">
      <h5>深层子组件</h5>
      <p>注入的主题: <span class="theme-value">{{ theme }}</span></p>
      <button class="toggle-btn" @click="toggleTheme">
        在此深层组件切换主题
      </button>
    </div>
    
    <div class="arrow-down">▼</div>
    
    <div class="deep-level">
      <p class="deep-text">直接从根组件获取数据</p>
      <p class="deep-text">无需 props 透传</p>
    </div>
  </div>
</template>

<style scoped>
.deep-child {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
}

.injected-info {
  background: white;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid #ddd;
  text-align: center;
  min-width: 200px;
}

.injected-info h5 {
  color: #495057;
  margin-bottom: 0.5rem;
}

.theme-value {
  font-weight: bold;
  color: #007bff;
}

.toggle-btn {
  background: #007bff;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  margin-top: 0.5rem;
  font-size: 0.9rem;
  transition: background 0.3s ease;
}

.toggle-btn:hover {
  background: #0056b3;
}

.arrow-down {
  font-size: 1.5rem;
  color: #6c757d;
}

.deep-level {
  background: #e9ecef;
  padding: 1rem;
  border-radius: 8px;
  text-align: center;
}

.deep-text {
  margin: 0.2rem 0;
  color: #495057;
  font-size: 0.9rem;
}
</style>